package com.ayou.eggguard.farm.controller;

import com.ayou.common.utils.PageBean;
import com.ayou.common.utils.Result;
import com.ayou.eggguard.farm.pojo.Doctor;
import com.ayou.eggguard.farm.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/doctor")
public class DoctorController {
    @Autowired
    private DoctorService doctorService;

    @GetMapping("/getDoctors")
    public Result<PageBean<Doctor>> getDoctors(Integer pageNum,
                                               Integer pageSize,
                                               @RequestParam(required = false) String doctorName){
        PageBean<Doctor> pb=doctorService.getDoctors(pageNum,pageSize,doctorName);
        return Result.success(pb);
    }

    @PostMapping("/add")
    public Result addDoctor(@RequestBody Doctor doctor){
        doctorService.add(doctor);
        return Result.success();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Doctor doctor){
        doctorService.update(doctor);
        return Result.success();
    }

    @GetMapping("/delete")
    public Result delete(Integer id){
        doctorService.delete(id);
        return Result.success();
    }
}
